/*
* @Author: chenggh
* @Date: 2025-06-14
* @Link to Problem : https://oj.haizeix.com/problem/45
*/
#include <iostream>
#include <string.h>
using namespace std;
int dp[1005][1005] = {0};
char x[1005], y[1005];
int main(){
	cin >> x + 1 >> y + 1;
	int n = strlen(x + 1), m = strlen(y + 1);
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			if(x[i] == y[j]) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
		}
	}
	cout << dp[n][m] << endl;
	return 0;
}